Skip to content

Fixed build_ext assumption that cross-compilation on Windows always uses MSVCCompiler#399

Open
Avasam wants to merge 1 commit intopypa:mainfrom
Avasam:patch-1
Open

Fixed build_ext assumption that cross-compilation on Windows always uses MSVCCompiler#399
Avasam wants to merge 1 commit intopypa:mainfrom
Avasam:patch-1

Conversation

@Avasam
Copy link
Contributor

@Avasam Avasam commented Feb 20, 2026

Fixes the following error if providing --plat-name when using msys2-mingw on Windows:

Traceback (most recent call last):
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel
    return _build_backend().build_wheel(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 438, in build_wheel
    return _build(['bdist_wheel'])
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 429, in _build
    return self._build_with_temp_dir(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 410, in _build_with_temp_dir
    self.run_setup()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 317, in run_setup
    exec(code, locals())
  File "<string>", line 1963, in <module>
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/__init__.py", line 117, in setup
    return distutils.core.setup(**attrs)  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
    dist.run_commands()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1000, in run_commands
    self.run_command(cmd)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/dist.py", line 1107, in run_command
    super().run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1019, in run_command
    cmd_obj.run()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line 370, in run
    self.run_command("build")
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 341, in run_command
    self.distribution.run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/dist.py", line 1107, in run_command
    super().run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1019, in run_command
    cmd_obj.run()
  File "<string>", line 354, in run
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 341, in run_command
    self.distribution.run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/dist.py", line 1107, in run_command
    super().run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1019, in run_command
    cmd_obj.run()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/command/build_ext.py", line 97, in run
    _build_ext.run(self)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 336, in run
    self.compiler.initialize(self.plat_name)
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MinGW32Compiler' object has no attribute 'initialize'

This could've been caught with static type checking, but attr-defined is currently disabled in mypy

# late initialization of compiler even if they shouldn't...)
self.plat_name != get_platform()
# Initialization is a MSVCCompiler specific concept
and hasattr(self.compiler, "initialize")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've done

Suggested change
and hasattr(self.compiler, "initialize")
and isinstance(MSVCCompiler, self.compiler)

But who knows if someone downstream added a custom non-MSVCCompiler with .initialize that relies on being called.

Or it could be considered so internal that it's fine to do the more "proper" check that also helps static checkers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant